package Jogo.Entities {
	import flash.display.MovieClip;
	import flash.geom.Point;
	
	/** Describe each tile of the map
	 * 
	 * @author Bruno Zumba (28/07/2011)
	 */
	public class Tile extends MovieClip {
		/* Indicates the type of the tile */
		public static const TURRET_POINT 	: int = 0; //It's a point to put turrets (w/o turret)
		public static const TURRET			: int = 1; //It's a turret
		public static const ENEMY_WAY		: int = 2; //It's a path the enemy can walk
		public static const GROUND			: int = 3; //Its none of the above. Just a ground
		public static const START_POINT		: int = 4; //It's where the enemies start
		public static const END_POINT		: int = 5; //It's where the enemies have to go
		
		private var type : int;
		
		/* If its a TURRET_POINT */
		private var turretPoint : TurretPoint;
		/* If its a TURRET */
		private var turret : Turret;
		/* If its a ENEMY_WAY, this vector indicates
		 * wich other tiles are connected to it */
		private var paths : Vector.<Tile>;
		/* If it's a ENEMY_WAY, contais the enemies 
		* currently in this tile. */
		private var enemies : Vector.<Enemy>;
		
		/* The center point of that tile based on the
		 * resolution of the game
		 */
		private var center : Point;
		
		
		public function Tile(center_p : Point, type_p : int = 3) : void{
			type = type_p;
			center = center_p;
			paths = new Vector.<Tile>;
			enemies = new Vector.<Enemy>;
		}
		
		/* Getters and setters */
		public function setTurret(newTurret : Turret):void{
			turret = newTurret;
		}
		public function getTurret(): Turret{
			return turret;
		}
		
		public function setTurretPoint(newTurretPoint : TurretPoint):void{
			turretPoint = newTurretPoint;
		}
		public function getTurretPoint(): TurretPoint{
			return turretPoint;
		}
		
		public function setPaths(newPaths:Vector.<Tile>):void{
			paths = newPaths;
		}
		public function getPaths() : Vector.<Tile>{
			return paths;
		}
		
		public function setType(newType : int):void{
			type = newType;
		}
		public function getType() : int{
			return type;
		}
		
		public function getCenter() : Point{
			return center;
		}
		
		public function insertEnemy(enemy_p : Enemy) : void{
			enemies.push(enemy_p);
		}
		public function removeEnemy(enemy_p : Enemy) : void{
			var i : int = enemies.indexOf(enemy_p, 0);
			var temp : Vector.<Enemy>;
			if (i >= 0){
				temp = enemies.splice(i, 1);
			}
		}
		public function getEnemies() : Vector.<Enemy>{
			return enemies;
		}
		
				
		/* Pushes a point into the paths vector */
		public function pathsPush(tile : Tile):void{
			paths.push(tile);
		}
		
	}
}